<%@ page import="com.jsp.pojo.Brand" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Properties" %>
<%@ page import="java.io.FileInputStream" %>
<%@ page import="javax.sql.DataSource" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="com.alibaba.druid.pool.DruidDataSourceFactory" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="com.jsp.pojo.Account" %><%--
  Created by IntelliJ IDEA.
  User: 张勤晓
  Date: 2023/10/27
  Time: 20:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>


<%
    //    List<Brand> brands = new ArrayList<Brand>();
//    brands.add(new Brand(1,"三只松鼠","三只松鼠",100,"三只松鼠，好吃不上火",1));
//    brands.add(new Brand(2,"优衣库","优衣库",200,"优衣库，服适人生",0));
//    brands.add(new Brand(3,"小米","小米科技有限公司",1000,"为发烧而生",1));
%>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<a href="/jsp-demo-1.0/AddServlet">增加</a><br>
<hr>
<table border="1" cellspacing="0" width="800">
    <tr>
        <th>序号</th>
        <th>品牌名称</th>
        <th>企业名称</th>
        <th>排序</th>
        <th>品牌介绍</th>
        <th>状态</th>
        <th>操作</th>


    </tr>
    <%
        Class.forName("com.mysql.jdbc.Driver");

        String url = "jdbc:mysql:///db1?useSSL=false";
        String user = "root";
        String password = "1234";


        Connection conn = DriverManager.getConnection(url, user, password);

        String sql = "select * from tb_brand";

        PreparedStatement pstmt = conn.prepareStatement(sql);

        ResultSet rs = pstmt.executeQuery();

        ArrayList<Brand> brands = new ArrayList<>();


        while (rs.next()) {

            Brand account = new Brand();

            int id = rs.getInt(1);
            String brandname = rs.getString(2);
            String companyname = rs.getString(3);
            int ordered = rs.getInt(4);
            String description = rs.getString(5);
            int status = rs.getInt(6);

            account.setId(id);
            account.setBrandName(brandname);
            account.setCompanyName(companyname);
            account.setDescription(description);
            account.setOrdered(ordered);
            account.setStatus(status);

            brands.add(account);
        }

    %>

    <%
        //        List<Brand> brands = (List<Brand>) request.getAttribute("brands");
//        ResultSet rs = (ResultSet) request.getAttribute("rs");
//        PreparedStatement pstmt =(PreparedStatement) request.getAttribute("pstmt");
//        Connection conn =(Connection) request.getAttribute("conn");
//                   List<Brand> brands =(List<Brand>) request.getRequestDispatcher("brands");
        for (int i = 0; i < brands.size(); i++) {
            Brand brand = brands.get(i);
    %>
    <tr align="center">
        <td><%=brand.getId()%>
        </td>
        <td><%=brand.getBrandName()%>
        </td>
        <td><%=brand.getCompanyName()%>
        </td>
        <td><%=brand.getOrdered()%>
        </td>
        <td><%=brand.getDescription()%>
        </td>
        <td><%=brand.getStatus() == 1 ? "启用" : "禁用"%>
        </td>
        <td><a href="delet.jsp?id=<%=brand.getId()%>">删除</a>

            <a href="alter.jsp?id=<%=brand.getId()%>">修改</a>
        </td>
    </tr>

    <%
        }
    %>

    <%
        //释放资源
        rs.close();
        pstmt.close();
        conn.close();
    %>

</table>

</body>
</html>
